package demo04_8LockProblem;

import java.util.concurrent.TimeUnit;

/**
 * @author kunkun
 * @className Test01
 * @Description0 场景：代码调用发短信线程，中间休息1s，在调用打电话线程，两个线程都用synchronized修饰
 * @Description1 1. 线程的执行顺序？（发短信，打电话）
 * @date 2025/3/5 19:36
 */
public class Test01 {

    public static void main(String[] args) throws InterruptedException {
        Phone phone = new Phone();

        new Thread(() -> {phone.sendMsg();}).start();

        TimeUnit.SECONDS.sleep(1);

        new Thread(() -> {phone.call();}).start();
    }

    static class Phone {
        public synchronized void sendMsg() {
            System.out.println("发短信");
        }
        public synchronized void call() {
            System.out.println("打电话");
        }
    }
}
